package cn.snow.boot.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @author liuwanxiang
 * @version 2018/09/13
 */
@Service
public class RedisReceiver {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public static final Logger log = LoggerFactory.getLogger(RedisReceiver.class);

    public void receiveMessage(String message) {
        //这里是收到通道的消息之后执行的方法
        log.info(new String(message.getBytes()));
    }

    /**
     * 向通道发送消息的方法
     */
    public void sendChannelMess(String channel, String message) {
        stringRedisTemplate.convertAndSend(channel, message);
    }

}
